package com.wjf.birdfish.util;

public class SecurityContextHolder {
	private static final SecurityContextHolder INSTANCE = new SecurityContextHolder();
	
	private ThreadLocal<SecurityContext> threadLocal = new ThreadLocal<SecurityContext>();
	
	private SecurityContextHolder() {}
	
	public static void setContext(SecurityContext securityContext) {
		INSTANCE.setSecurityContext(securityContext);
	}
	
	public static SecurityContext getContext() {
		return INSTANCE.getSecurityContext();
	}
	
	public static SecurityContext createContext() {
		return new SecurityContext();
	}
	
	public static void clearContext() {
		INSTANCE.clearSecurityContext();
	}
	
	private void clearSecurityContext() {
		this.threadLocal.remove();
	}

	private void setSecurityContext(SecurityContext securityContext) {
		this.threadLocal.set(securityContext);
	}
	
	private SecurityContext getSecurityContext() {
		return this.threadLocal.get();
	}
}
